<?php
function get_blog_posts() {
    $retval = array();
        
    $db = new mysqli('200.58.126.52', 'deviales_blog', '1337PVPftw');

    if ($db->connect_errno)
        return array();
        
    $db->select_db('deviales_blogrojo');

    $query = 'SELECT post_title, post_name FROM wp_posts WHERE post_status="publish" ORDER BY post_date DESC';
    $blog_base_url = 'http://blog.mercadovial.com/';
    
    if ($result = $db->query($query . ' LIMIT 3')) {
        while ($row = $result->fetch_assoc()) {
            $row['post_url'] = $blog_base_url.$row['post_name'];
            $retval[] = $row;
        }
    }
    
    $db->select_db('deviales_blogverde');
    $blog_base_url = 'http://blogverde.mercadovial.com/';
    
    if ($result = $db->query($query . ' LIMIT 2')) {
        while ($row = $result->fetch_assoc()) {
            $row['post_url'] = $blog_base_url.$row['post_name'];
            $retval[] = $row;
        }
    }
    return $retval;
}

?>

<?php
    $posts = @get_blog_posts();
    
    if (empty($posts)) {
        echo 'No Blog posts available';
    }
    else 
    {
        echo '<ul id="novedades_ul" style="overflow-y:scroll; height: 195px;">';

        foreach ($posts as $post) {
            echo '<li><a href="'.htmlentities($post['post_url']).'" target="_blank">'.htmlentities($post['post_title']).'</a></li>';
        }
        
        echo '</ul>';
    }
?>
